package tech.lixinlei.java.trycatchfinally;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
public class TryDemo {

    public static void main(String[] args) {
        System.out.println(testTry());
    }

    private static String testTry() {
        String feishuResponse = "'{\"Extra\":null,\"StatusCode1\":0,\"StatusMessage\":\"success\"}";
        try {
            Integer statusCode = JSON.parseObject(feishuResponse).getInteger("StatusCode");
            if (statusCode != null && statusCode == 0) {
                return "success";
            }
        } catch (Exception e) {
            // 走完异常处理逻辑还是会走 return 的
            log.error("飞书机器人 WebHook 返回结果 JSON 解析失败");
        }
        return "fail";
    }

}
